﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SAM.Configuration.Domain
{
    public class JSONConfigurationBuild:AbstractConfigurationBuild
    {
        public JSONConfigurationBuild():base()
        {

        }
        public JSONConfigurationBuild(string baseFilePath) : base(baseFilePath)
        {

        }

        public override T Read<T>(string fileName)
        {
            string fullPath = this.FullPath(fileName);
            bool exists = this.ExistsFile(fullPath);
            if (!exists) return default(T);
            return Newtonsoft.Json.JsonConvert.DeserializeObject<T>(this.ReadFile(fullPath));
        }

        public override void Write<T>(string fileName, T data)
        {
            string fullPath = this.FullPath(fileName);
            if (data == null) return;
            string content = Newtonsoft.Json.JsonConvert.SerializeObject(data);
            this.CreateFile(fullPath, content, Encoding.UTF8);
        }
    }
}
